<include file="public@header"/>
<link href="/themes/admin_simpleboot3/public/assets/themes/flatadmin/modal.css" rel="stylesheet" type="text/css">
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
    
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="layui-input" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="layui-input" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
               style="width: 200px;" title="文件名称">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
        <a href="javascript:uploadOne('附件上传','#file-{id}','file');">替换</a>
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>
<div class="layui-fluid js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('AdminBranchArticle/index',array('category'=>$categories[0]['id']))}">文章管理</a></li>
        <li>
            <a href="{:url('AdminBranchArticle/add',array('category'=>$categories[0]['id']))}">添加文章</a>
        </li>
        <li class="active"><a href="#A" data-toggle="tab">编辑文章</a></li>
        <eq name="extend" value="1">
            <li><a href="#B" data-toggle="tab">扩展信息</a></li>
        <else />
        </eq>
    </ul>
    <form action="{:url('AdminBranchArticle/editPost')}" method="post" class="layui-form js-ajax-form margin-top-20">
    <div class="tab-content">
        <div class="tab-pane active" id="A">
            <div class="row">
                <div class="col-md-9">
                    <table class="table table-bordered">
                        <tr>
                            <th width="80">基地<span class="form-required">*</span></th>
                            <td>
                                <select class="layui-input" name="post[branch][]" multiple="" style="width:auto;height:134px;">
                                    <option value='0'>请选择</option>
                                    {$branch_list}
                                </select>
                                <p class="layui-word-aux">windows：按住 Ctrl 按钮来选择多个选项,Mac：按住 command 按钮来选择多个选项</p>
                            </td>
                        </tr>
                        <tr>
                            <th width="100">分类<span class="form-required">*</span></th>
                            <td>
                                <select class="layui-input" name="post[categories]" style="width: 140px;">
                                    <option value='0'>请选择</option>
                                    {$category_tree|default=''}
                                </select>
                            </td>
                        </tr>
                        <if condition="in_array('title',$field_list)">
                        <tr>
                            <th>标题<span class="form-required">*</span></th>
                            <td>
                                <input type="hidden" name="post[id]" value="{$post.id}">
                                <input class="layui-input" id="title" type="text" name="post[post_title]"
                                        value="{$post.post_title}" placeholder="请输入标题"/>
                            </td>
                        </tr>
                        </if>

                        <if condition="in_array('keywords',$field_list)">
                        <tr>
                            <th>关键词</th>
                            <td>
                                <input class="layui-input" type="text" id="keywords" name="post[post_keywords]"
                                       value="{$post['post_keywords']}" placeholder="请输入关键字">
                                <p class="layui-word-aux">多关键词之间用英文逗号隔开</p>
                            </td>
                        </tr>
                        </if>
              
                        <if condition="in_array('excerpt',$field_list)">
                        <tr>
                            <th>摘要</th>
                            <td>
                                <textarea class="layui-input" id="post_excerpt" name="post[post_excerpt]" style="height: 50px;"
                                          placeholder="请填写摘要">{$post.post_excerpt}</textarea>
                            </td>
                        </tr>
                        </if>

                        <if condition="in_array('href',$field_list)">
                        <tr>
                            <th>转向链接</th>
                            <td>
                                <!-- <input type="text" name="post[href]" id="href" value="{$post.href}" style="width: 400px" placeholder="http://"> -->
                                <input class="layui-input" type="text" name="post[href]" value="{$post['href']}" placeholder="http://">
                                       <p class="layui-word-aux">可跳转到指定地址</p>
                                
                            </td>
                        </tr>
                        </if>

                        
                        <if condition="in_array('content',$field_list)">
                        <tr>
                            <th>内容</th>
                            <td>
                                <script type="text/plain" id="content" name="post[post_content]">{$post.post_content}</script>
                            </td>
                        </tr>
                        </if>

                        <if condition="in_array('pdf',$field_list)">
                        <tr>
                            <th>上传文件</th>
                            <td>
                                <ul id="file_pdf" class="pic-list list-unstyled form-inline">
                                    <input id="file-pdf" type="hidden" name="post[file_url]"  value="{$post.file_url}">
                                    <input class="layui-input" id="file-pdf-name" type="text" name="post[file_name]" style="width: 400px;" title="文件名称" value="{$post.file_name}" readonly>
                                    <a href="javascript:uploadOne('pdf上传','#file-pdf','document');">选择文件</a>
                                    <notempty name="post['file_url']">
                                        <a href="{:cmf_get_file_download_url($post['file_url'])}" target="_blank">下载</a>
                                    </notempty>
                                    <a href="javascript:(function(){$('#file-pdf').val('');$('#file-pdf-name').val('');})();">移除</a>
                                </ul>
                            </td>
                        </tr>
                        </if>
                        
                        <if condition="in_array('video',$field_list)">
                        <tr>
                            <th>视频</th>
                            <td>
                                <ul id="file_video" class="pic-list list-unstyled form-inline">
                                    <input id="file-video" type="hidden" name="post[file_url]"  value="{$post.file_url}">
                                    <input class="layui-input" id="file-video-name" type="text" name="post[file_name]" style="width: 400px;" title="文件名称" value="{$post.file_name}" readonly>
                                    <a href="javascript:uploadOne('视频上传','#file-video','video');">选择文件</a>
                                    <notempty name="post['file_url']">
                                        <a href="{:cmf_get_file_download_url($post['file_url'])}" target="_blank">下载</a>
                                    </notempty>
                                    <a href="javascript:(function(){$('#file-video').val('');$('#file-video-name').val('');})();">移除</a>
                                </ul>
                            </td>
                        </tr>
                        </if>

                        <if condition="in_array('album',$field_list)">
                        <tr>
                            <th>相册</th>
                            <td>
                                <ul id="photos" class="pic-list list-unstyled form-inline">
                                    <notempty name="post.more.photos">
                                        <foreach name="post.more.photos" item="vo">
                                            <php>$img_url=cmf_get_image_preview_url($vo['url']);</php>
                                            <li id="saved-image{$key}">
                                                <input id="photo-{$key}" type="hidden" name="photo_urls[]"
                                                       value="{$vo.url}">
                                                <input class="layui-input" id="photo-{$key}-name" type="text"
                                                       name="photo_names[]"
                                                       value="{$vo.name|default=''}" style="width: 200px;" title="图片名称">
                                                <img id="photo-{$key}-preview"
                                                     src="{:cmf_get_image_preview_url($vo['url'])}"
                                                     style="height:36px;width: 36px;"
                                                     onclick="parent.imagePreviewDialog(this.src);">
                                                <a href="javascript:uploadOneImage('图片上传','#photo-{$key}');">替换</a>
                                                <a href="javascript:(function(){$('#saved-image{$key}').remove();})();">移除</a>
                                            </li>
                                        </foreach>
                                    </notempty>
                                </ul>
                                <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
                                   class="btn btn-sm btn-default">选择图片</a>
                            </td>
                        </tr>
                        </if>

                    </table>
                    <div class="layui-form-item">
                        <div class="layui-col-smoffset-2 layui-col-sm10">
                            <button type="submit" class="layui-btn layui-btn-normal js-ajax-submit" style="display:none;" id="js-ajax-submit">{:lang('SAVE')}</button>
                            <button type="button" class="layui-btn layui-btn-normal" onclick="CheckSubmit();" id="add-key">{:lang('SAVE')}</button>
                            <button type="button" class="layui-btn layui-btn-normal content-preview" onclick="contentPreview(editorcontent,'title','published_time');" id="add-key">{:lang('PREVIEW')}</button>
                            <a class="btn btn-default" href="javascript:history.back(-1);">{:lang('BACK')}</a>
                        </div>
                    </div>
                </div>

                <div class="col-md-3">
                    <table class="table table-bordered">
                        <if condition="in_array('thumb',$field_list)">
                        <tr>
                            <th>缩略图</th>
                        </tr>
                        <tr>
                            <td>
                                <div style="text-align: center;" class="upload-image">
                                    <input type="hidden" name="post[more][thumbnail]" id="thumbnail"
                                           value="{$post.more.thumbnail|default=''}">
                                    <a href="javascript:uploadOneImage('图片上传','#thumbnail');">
                                        <if condition="empty($post.more.thumbnail)">
                                            <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                                 id="thumbnail-preview"
                                                 width="135" style="cursor: pointer"/>
                                            <else/>
                                            <img src="{:cmf_get_image_preview_url($post.more.thumbnail)}"
                                                 id="thumbnail-preview"
                                                 width="135" style="cursor: pointer"/>
                                        </if>
                                    </a>
                                    <input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
                                </div>
                            </td>
                        </tr>
                        </if>

                        <notempty name="categories">
                            <tr>
                                <th>缩略图推荐尺寸</th>
                            </tr>
                            <tr>
                                <td>
                                    <table style="width:100%;" class="thumb-size">
                                        <tr>
                                            <td style="border:1px solid #ddd;text-align:center;">分类名</td>
                                            <td style="border:1px solid #ddd;text-align:center;">尺寸</td>
                                        </tr>    
                                    <foreach name="categories" item="vo">
                                        <tr>
                                            <td style="border:1px solid #ddd;text-align:center;">{$vo.name}</td>
                                            <td style="border:1px solid #ddd;text-align:center;">{$vo.thumb_size}</td>
                                        </tr>
                                    </foreach>
                                    </table>
                                </td>
                            </tr>
                        </notempty>

                        <if condition="$big_thumb eq 1">
                        <tr>
                            <td><b>缩略图（大）</b></td>
                        </tr>
                        <tr>
                            <td>
                                <div style="text-align: center;" class="upload-image">
                                    <input type="hidden" name="post[more][big_thumbnail]" id="big_thumbnail"
                                           value="{$post.more.big_thumbnail|default=''}">
                                    <a href="javascript:uploadOneImage('图片上传','#big_thumbnail');">
                                        <if condition="empty($post.more.big_thumbnail)">
                                            <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                                 id="big_thumbnail-preview"
                                                 width="135" style="cursor: pointer"/>
                                            <else/>
                                            <img src="{:cmf_get_image_preview_url($post.more.big_thumbnail)}"
                                                 id="big_thumbnail-preview"
                                                 width="135" style="cursor: pointer"/>
                                        </if>
                                    </a>
                                    <input type="button" class="btn btn-sm" value="取消图片" onclick="$('#big_thumbnail-preview').attr('src','__TMPL__/public/assets/images/default-thumbnail.png');$('#big_thumbnail').val('');return false;">
                                </div>
                            </td>
                        </tr>
                        </if>

                        <tr>
                            <th>发布时间</th>
                        </tr>
                        <tr>
                            <td>
                                <input class="layui-input js-layui-datetime" type="text" name="post[published_time]"
                                       value="{:date('Y-m-d H:i',$post['published_time'])}" id="published_time">
                            </td>
                        </tr>
                        <!--
                        <tr>
                            <th>评论</th>
                        </tr>
                        <tr>
                            <td>
                                <label style="width: 88px"><a
                                        href="javascript:openIframeDialog('{:url('comment/commentadmin/index',array('post_id'=>$post['id']))}','评论列表')">查看评论</a></label>
                            </td>
                        </tr>
                        -->

                        <notempty name="field_status_list">
                            <tr>
                                <th>状态</th>
                                <php>
                                    
                                    $is_top_yes  = $post['is_top']==1?"checked":"";
                                    $is_show_yes = $post['is_show']==1?"checked":"";
                                </php>
                            </tr>
                            <!-- <tr style="display:none;">
                                <td>
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" name="post[post_status]" value="1" {$status_yes}>发布
                                        </label>
                                    </div>
                                </td>
                            </tr> -->

                            <if condition="in_array('status_recom',$field_list)">
                            <tr>
                                <td>
                                    <div class="checkbox">
                                        <label>
                                            <input type="checkbox" name="post[is_show]" value="1" {$is_show_yes}>显示
                                        </label>
                                    </div>
                                </td>
                            </tr>
                            </if>
                            <if condition="in_array('status_is_top',$field_list)">
                            <tr>
                                <td>
                                    <div class="checkbox">
                                        <label><input type="checkbox" name="post[is_top]" value="1" {$is_top_yes}>置顶</label>
                                    </div>
                                </td>
                            </tr>
                            </if>

                        </notempty>

                        <if condition="in_array('template',$field_list)">
                        <tr>
                            <th>文章模板</th>
                        </tr>
                        <tr>
                            <td>
                                <select class="layui-input" name="post[more][template]" id="more-template-select">
                                    <option value="">请选择模板</option>
                                    <foreach name="article_theme_files" item="vo">
                                        <php>$value=preg_replace('/^portal\//','',$vo['file']);</php>
                                        <option value="{$value}">{$vo.name} {$vo.file}.html</option>
                                    </foreach>
                                </select>
                            </td>
                        </tr>
                        </if>

                    </table>
                </div>
            </div>
            
        </div>
 
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript" src="__STATIC__/js/modal.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
    $(function () {
        if( $('#content').length ){
            $('.content-preview').show();
            editorcontent = new baidu.editor.ui.Editor();
            editorcontent.render('content');
            try {
                editorcontent.sync();
            } catch (err) {
            }
        }
        $('.btn-cancel-thumbnail').click(function () {
            $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
            $('#thumbnail').val('');
        });

        $('#more-template-select').val("{$post.more.template|default=''}");
    });

    function doSelectCategory() {
        var selectedCategoriesId = $('#js-categories-id-input').val();
        openIframeLayer("{:url('AdminCategory/select')}?ids=" + selectedCategoriesId, '请选择分类', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedCategories = iframeWin.confirm();
                if (selectedCategories.selectedCategoriesId.length == 0) {
                    layer.msg('请选择分类');
                    return;
                }
                $('#js-categories-id-input').val(selectedCategories.selectedCategoriesId.join(','));
                $('#js-categories-name-input').val(selectedCategories.selectedCategoriesName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }

    function CheckSubmit(){
        var title           = $("#title").val();
        var keywords        = $("#keywords").val();
        var post_excerpt    = $("#post_excerpt").val();
        if( $('#content').length ){
            var content     = editorcontent.getPlainTxt();
        }else{
            var content = '';
        }
        var href = "{:url('goods/AdminGoods/replace')}";
        var data = {'data':'TITLE:'+title+',KEYWORDS:'+keywords+',ABSTRACT:'+post_excerpt+',CONTENT:'+content};
        $.ajax({
            url:  href,
            data: data,
            type: 'post',
            dataType: 'json',
            beforeSend:function(){
            },
            success: function (res) {
                if(res[0] !=1){
                    var str = '';
                    for(var p in res){
                        str = str+res[p];
                    }
                    str = str+'<p style="color:red;">是否确认替换？</p>';
                    $("#add-key").createModal({
                        background: "#000",//设定弹窗之后的覆盖层的颜色
                        width: "500px",//设定弹窗的宽度
                        height: "auto",//设定弹窗的高度
                        resizable: true,//设定弹窗是否可以拖动改变大小
                        move: false,//规定弹窗是否可以拖动
                        bgClose: false,//规定点击背景是否可以关闭
                        html: "<div class='modal-promot-mess'>提示信息</div>"
                                +"<div class='messge'>"+str+"</div>"
                                 +"<p class='insure-btn-con'><span class='sure-btn' onclick='tijiao()'>确定</span><span class='cancel-btn modal-close'>取消</span></p>",
                        
                    });
                }else{
                    $('#js-ajax-submit').click();
                }
            }
        });
    }
    function tijiao(){
        $('#js-ajax-submit').click();
    };
</script>
</body>
</html>
